<template>
	<view class="lease_restitution">
		<view class="container mt20">
			<lease-order-goods :image="orderDetail.lease_goods_info.image">
				<template #name>{{ orderDetail.goods_name }}</template>
				<!-- <template #name>{{ orderDetail.goods_name }}</template> -->
				<template #specs>
					<text class="mr10">规格：租完可还/买断</text>
					<!-- <text>{{item.order_goods.goods_item_str}}{{ getPeriodsUnit(item.periods_attribute) }}</text> -->
					<text>{{orderDetail.lease_goods_item_str}}</text>
				</template>
				<template #tenancy>
					<text class="mr10">租期：</text>
					<text>{{orderDetail.lease_start_date}}至{{orderDetail.lease_end_date}}</text>
				</template>
				<template #num>
					<text class="mr10">数量：</text>
					<text>{{orderDetail.goods_num}}</text>
				</template>
			</lease-order-goods>
		</view>

		<view class="uni-list">
			<view class="uni-list-cell row-between">
				<view class="uni-list-cell-left">
					归还方式
				</view>
				<view class="row">
					<picker @change="bindPickerChange" :value="index" :range="array" class="uni-picker"
						:disabled="return_info.status==3?false:true">
						<view class="uni-input">{{array[index]}}</view>
					</picker>
					<u-icon name="arrow-right" color="#00000099;"></u-icon>
				</view>
			</view>
		</view>
		<view class="return-merchant row-between mt20" v-if="index==2">
			<view class="lg mer-address">
				商家地址
			</view>
			<view class="address-detail">
				<view class="">
					{{merchantAddress}}
				</view>
				<view class="address-copy" @click="copyText">
					<image src="/bundle/static/images/ghCopy.png" mode="aspectFit"></image>复制
				</view>
			</view>
		</view>
		<view class="return-prompt mt20">
			提示:请以原包装归还设备，未按原包装归还的，商家有权扣除相应包装费用
		</view>
		<view class="container row-between mt20">
			<view class="lg mer-address">
				审核状态
			</view>
			<view :class="return_info.status==1?'examine':return_info.status==3?'noexamine':''">
				• {{return_info.status==1?'待审核':return_info.status==3?'不通过':''}}
			</view>
		</view>
		<view class="return-merchant row-between mt10" v-if="return_info.status==3">
			<view class="lg mer-address">
				审核意见
			</view>
			<view class="address-detail">
				<view class="">
					{{return_info.verify_desc}}
				</view>
			</view>
		</view>
		<view class="express mt20" v-if="index==1">
			<view class="row-between express-delivery lg">
				<text>快递单号</text>
				<input type="text" v-model="invoice_no" placeholder="请填写退货快递单号" />
			</view>
			<view class="row-between express-delivery lg">
				<text>快递公司</text>
				<input type="text" v-model="express_name" placeholder="请填写快递公司" />
			</view>
		</view>
		<view class="card-button" v-if="return_info.status==3">
			<u-button type="primary" shape="circle" plain @click="confirmReturn">修改</u-button>
		</view>
	</view>
</template>

<script>
	import {
		getreturnDetail,
		orederReturn
	} from '@/api/lease.js'
	export default {
		data() {
			return {
				returnId: 0, //归还订单id
				orderDetail: {},
				orderAddress: {},
				returnShow: false,
				returnSelector: [],
				array: ['请选择归还方式', '物流归还', '线下归还'],
				index: 0,
				merchantAddress: "", //商家地址
				express_name: '', //快递公司
				invoice_no: '', //物流单号
				return_info: {}
			}
		},

		methods: {
			// 初始化数据
			indata() {
				getreturnDetail({
					id: this.returnId
				}).then(res => {
					if (res.code != 1) return;
					this.orderDetail = res.data.goods_info;
					this.orderAddress = res.data.shop_address;
					this.return_info = res.data.return_info;
					this.index = res.data.return_info.return_type;
					this.invoice_no = res.data.return_info.invoice_no;
					this.express_name = res.data.return_info.express_name;
					this.merchantAddress = res.data.shop_address.contact + ' ' + res.data.shop_address.mobile +
						' ' + res.data.shop_address.address
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},

			// 复制地址
			copyText() {
				const text = this.merchantAddress;
				uni.setClipboardData({
					data: text,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'success',
							duration: 2000
						});
					},
					fail: function() {
						uni.showToast({
							title: '复制失败',
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			// 按下确认按钮
			confirmReturn() {
				console.log('确认')
				const id = this.returnId;
				uni.navigateTo({
					url: `/bundle/pages/lease_goods_return/lease_goods_restitution?id=${id}`
				})
				return;

				if (this.index == 0) {
					this.$toast({
						title: '请先选择归方式！',
						icon: 'none'
					});
					return
				}
				if (this.index == 1) {
					if (this.invoice_no == '') {
						this.$toast({
							title: '请输入物流订单！',
							icon: 'none'
						});
						return
					}
					if (this.express_name == '') {
						this.$toast({
							title: '请输入快递公司！',
							icon: 'none'
						});
						return
					}
					// 物流归还
					orederReturn({
						id: this.returnId,
						return_type: this.index,
						express_name: this.express_name,
						invoice_no: this.invoice_no
					}).then(res => {
						if (res.code == 1) {
							this.$toast({
								title: '提交成功！',
								icon: 'success'
							});

							uni.navigateBack()
						}
					})
				} else {
					// 线下归还
					orederReturn({
						id: this.returnId,
						return_type: this.index,
					}).then(res => {
						if (res.code == 1) {
							this.$toast({
								title: '提交成功！',
								icon: 'success'
							});
							setTimeout(() => uni.navigateBack(), 500);
						}
					})
				}



			}
		},

		onLoad(options) {
			const id = options.id
			this.returnId = id;
		},

		onShow() {
			this.indata()
		}
	}
</script>

<style lang="scss" scoped>
	.lease_restitution {
		padding: 0 20rpx 0 20rpx;
	}

	.container {
		padding: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 14rpx;
		background-color: #FFFFFF;
	}

	.uni-list-cell {
		background-color: #FFFFFF;
		padding: 32rpx 24rpx;
		border-radius: 24rpx;
		font-size: 32rpx;
		font-weight: 500;
	}

	.uni-list-cell-db {
		flex: 1;
		text-align: right;
		align-items: baseline;

	}

	.uni-picker {
		width: 100%;
	}

	.uni-input {
		color: #00000099;
		padding-right: 6rpx;
	}

	.return-merchant {
		background-color: #FFFFFF;
		padding: 32rpx 24rpx;
		border-radius: 24rpx;
		font-size: 32rpx;
		align-items: flex-start;
		align-self: stretch;

		.address-detail {
			align-self: stretch;
			color: #00000066;
			text-align: right;
			font-size: 28rpx;
			font-style: normal;
			font-weight: 500;
			line-height: 40rpx;
			flex: 1;
			margin-left: 88rpx;
		}

		.mer-address {
			color: #000000e6;
			font-weight: 500;
		}

		.address-copy {
			color: #2482ee;

			font-size: 28rpx;
			font-style: normal;
			font-weight: 500;
			line-height: 40rpx;
			display: inline-block;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 8rpx;
				vertical-align: sub;

			}

		}
	}

	.return-prompt {
		display: flex;
		padding: 16rpx 14rpx;
		justify-content: center;
		align-items: center;
		align-self: stretch;
		border-radius: 24rpx;
		background: #c38b611a;
		color: #c38b61;
		font-size: 24rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 32rpx;
	}

	.examine {
		color: #c38b61;
		text-align: center;
		font-size: 28rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 28px;
	}

	.noexamine {
		color: #E63333;
		text-align: center;
		font-size: 28rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 28px;
	}

	.express {
		background-color: #FFFFFF;
		border-radius: 24rpx;
		padding: 0 24rpx;
	}

	.express-delivery {
		padding: 32rpx 0;
		text-align: right;

		input {
			flex: 1;
			background-color: #ffffff;
			color: #000000e6;
		}
	}

	.express-delivery:nth-child(1) {
		border-bottom: 2rpx solid #00000005;
		;
	}

	.card-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background: #ffffff;
		padding: 30rpx;
		z-index: 1000;
		/* 确保不被其他元素覆盖 */
	}
</style>